<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>修改页面</title>
    <link rel="stylesheet" href="bootstrap.min.css">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <style>

    </style>
</head>

<body>
    <div class="container">
        <h1>修改信息</h1>
        <hr>
        <div class="col-sm-4">
            <div class="form-group">
                <label>请修改昵称</label>
                <input type="text" class="form-control" id="name" placeholder="请修改昵称">
            </div>
            <div class="form-group">
                <label>请修改微信</label>
                <input type="text" class="form-control" id="weixin" placeholder="请修改微信">
            </div>
            <div class="form-group">
                <label>请修改电话</label>
                <input type="number" class="form-control" id="phone" placeholder="请修改电话">
            </div>
            <div class="form-group">
                <label>请修改人数</label>
                <input type="number" class="form-control" id="num" placeholder="请修改人数">
            </div>
            <button type="submit" class="btn btn-success" onclick="ok()">确认修改</button>
            <button type="submit" class="btn btn-danger" onclick="shanchu()">删除</button>
            <a href="index.html" type="submit" class="btn btn-default ">返回</a>
        </div>
    </div>
    <script src="jquery-1.12.4.js"></script>
    <script>
    var url = "https://shenyuxf.top/"

    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    // 调用方法
    var _id = GetQueryString("_id");


    //拿到相对的id 的值
    $.ajax({
        url: url + 'findOne?_id=' + _id,
        type: 'GET',
        success: (data) => {
            console.log(data)

            $("#name").val(data[0].name);
            $("#weixin").val(data[0].weixin);
            $("#phone").val(data[0].phone);
            $("#num").val(data[0].num);

        },
        dataType: 'json',
        error: (xhr, status, error) => {

        }
    })

    //确认修改



    function ok() {

        var name = $("#name").val();
        var weixin = $("#weixin").val();
        var phone = $("#phone").val();
        var num = $("#num").val();
        $.ajax({
            url: `${url}update?_id=${_id}&name=${name}&weixin=${weixin}&phone=${phone}&num=${num}`,
            type: 'GET',
            success: (data) => {
                alert("修改成功")
                window.location = "index.html"
            },
            dataType: 'text',
            error: (xhr, status, error) => {
                console.log(status)
            }
        })

    }

        function shanchu() {

       
        $.ajax({
            url: `${url}remove?_id=${_id}`,
            type: 'GET',
            success: (data) => {
                alert("删除成功")
                window.location = "index.html"
            },
            dataType: 'text',
            error: (xhr, status, error) => {
                console.log(status)
            }
        })

    }
    </script>
</body>

</html>
